<template>
  <el-descriptions
      class="movie-detail"
      :column="1"
      border
  >
    <el-descriptions-item label="电影名称">
      {{ movieData.movie.name }}
    </el-descriptions-item>

    <el-descriptions-item label="原始名称">
      {{ movieData.movie.origin_name }}
    </el-descriptions-item>

    <el-descriptions-item label="简介">
      <div v-html="movieData.movie.content"></div>
    </el-descriptions-item>

    <el-descriptions-item label="类型">
      <el-tag
          v-for="cat in movieData.movie.category"
          :key="cat.id"
          class="mx-1"
      >
        {{ cat.name }}
      </el-tag>
    </el-descriptions-item>

    <el-descriptions-item label="国家/地区">
      <el-tag
          v-for="country in movieData.movie.country"
          :key="country.id"
          type="success"
          class="mx-1"
      >
        {{ country.name }}
      </el-tag>
    </el-descriptions-item>

    <el-descriptions-item label="状态">
      <el-tag :type="getStatusType(movieData.movie.status)">
        {{ getStatusText(movieData.movie.status) }}
      </el-tag>
    </el-descriptions-item>

    <el-descriptions-item label="播放信息">
      <div class="play-info">
        <p>
          <span class="label">集数：</span>
          {{ movieData.movie.episode_current }} / {{ movieData.movie.episode_total }}
        </p>
        <p>
          <span class="label">时长：</span>
          {{ movieData.movie.time }}
        </p>
        <p>
          <span class="label">语言：</span>
          {{ movieData.movie.lang }}
        </p>
        <p>
          <span class="label">画质：</span>
          {{ movieData.movie.quality }}
        </p>
      </div>
    </el-descriptions-item>

    <el-descriptions-item label="更新时间">
      {{ formatDate(movieData.movie.modified.time) }}
    </el-descriptions-item>

    <el-descriptions-item label="海报">
      <el-image
          :src="movieData.movie.poster_url"
          :preview-src-list="[movieData.movie.poster_url]"
          fit="contain"
          class="poster-image"
      />
    </el-descriptions-item>

    <el-descriptions-item label="评分信息">
      <div class="rating-info">
        <el-rate
            v-model="movieData.movie.tmdb.vote_average"
            :max="10"
            disabled
            show-score
        />
        <p class="vote-count">
          {{ movieData.movie.tmdb.vote_count }} 人评分
        </p>
      </div>
    </el-descriptions-item>

    <!-- 可以查看原始JSON的折叠面板 -->
    <el-descriptions-item>
      <el-collapse>
        <el-collapse-item title="查看原始JSON数据">
          <pre class="json-content">{{ JSON.stringify(movieData, null, 2) }}</pre>
        </el-collapse-item>
      </el-collapse>
    </el-descriptions-item>
  </el-descriptions>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  movieData: {
    type: Object,
    required: true
  }
})

const getStatusType = (status) => {
  const statusMap = {
    'trailer': 'warning',
    'ongoing': 'success',
    'completed': 'info'
  }
  return statusMap[status] || 'info'
}

const getStatusText = (status) => {
  const statusMap = {
    'trailer': '预告片',
    'ongoing': '连载中',
    'completed': '已完结'
  }
  return statusMap[status] || status
}

const formatDate = (dateString) => {
  return new Date(dateString).toLocaleString()
}
</script>

<style scoped>
.movie-detail {
  max-width: 800px;
  margin: 0 auto;
}

.poster-image {
  max-width: 300px;
  max-height: 400px;
}

.play-info {
  display: grid;
  gap: 8px;
}

.play-info .label {
  font-weight: bold;
  margin-right: 8px;
}

.rating-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vote-count {
  color: #909399;
  font-size: 14px;
}

.mx-1 {
  margin: 0 4px;
}

.json-content {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: monospace;
  font-size: 12px;
  background: #f5f7fa;
  padding: 12px;
  border-radius: 4px;
}
</style>